package com.qingcheng.controller.goods;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Brand;
import com.qingcheng.service.goods.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//@RestController 合并了@RequestBody 和 @Controller 注解
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Reference
    private BrandService brandService;

    @GetMapping("/findAll")
    public List<Brand> findAll() {
        return brandService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Brand> findPage(int page, int size) {
        /*
         *   返回 总记录数和结果集（泛型）
         * */
        return brandService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Brand> fingList(@RequestBody Map<String, Object> searchMap) {
        return brandService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Brand> findPage(@RequestBody Map<String, Object> searchMap, Integer page, Integer size) {
        return brandService.findPage(searchMap, page, size);
    }

    @GetMapping("/findById")
    public Brand findById(Integer id){
        return brandService.findById(id);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Brand brand){
        brandService.add(brand);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return new Result();
    }

    @GetMapping("/deleteById")
    public Result deleteById(Integer id){
        brandService.deleteById(id);
        return new Result();
    }

    /*@PostMapping("/delete")
    public Result delete(@RequestBody Brand brand){
        brandService.deleteByPrimaryKey(brand);
        return new Result();
    }*/

}
